<?php
/**
 * Created by PhpStorm.
 * User: jacob
 * Date: 18-10-15
 * Time: 上午11:49
 * 获取用户个人信息
 */
namespace Api\Home;

use Common\HttpStatus;
use Common\PlutoApi;
use Common\Request;
use Common\RequestApi;
use Common\Response;
use Common\ResponseApi;
use Db\Home\AccountUser;
use DB\Home\AccountUserInfo;

class GetUserInfoRequest extends RequestApi{
}

class GetUserInfoResponse extends ResponseApi{
  public $id;
  public $name;
  public $phone;
  public $email;
  public $nickname;
}

class GetUserInfo extends PlutoApi{
  protected function run(Request $request, Response $response) {
    $uid = $request->uid;
    $info = new AccountUserInfo();
    $user = new AccountUser($uid);
    if(!$user->getInfo($info)){
      $response->httpStatus = HttpStatus::NOT_FOUND;
      $response->httpMessage = "user infomation is not found";
      return;
    }
    $response->data = new GetUserInfoResponse();
    $response->data->id = (string)$info->_id;
    $response->data->email = $info->email??null;
    $response->data->phone = $info->phone??null;
    $response->data->name = $info->name??null;
    $response->data->nickname = $info->nickname??null;
  }
}